#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# Copyright [Gtlions Lai].
# Create Date:
# Update Date:
"""summarization ahout this script.

detail ahout this script

   Class(): summarization about Class
   ...
   function(): summarization about function
   ...
"""
__authors__ = '"Gtlions Lai" <gtlions.l@qq.com>'

import sys

from PyQt4 import QtGui, QtCore, QtSql

import kexshop.gtcom.dbpool


QtCore.QTextCodec.setCodecForTr(QtCore.QTextCodec.codecForName("utf8"))

class SpinBoxDelegate1(QtGui.QItemDelegate):
    def createEditor(self, parent, option, index):
        editor = QtGui.QSpinBox(parent)
        editor.setMinimum(0)
        editor.setMaximum(100)
        print 'spinbox'
        return editor

    def setEditorData(self, spinBox, index):
        value = index.model().data(index, QtCore.Qt.EditRole).toInt()[0]

        spinBox.setValue(value)

    def setModelData(self, spinBox, model, index):
        spinBox.interpretText()
        value = spinBox.value()

        model.setData(index, value, QtCore.Qt.EditRole)

    def updateEditorGeometry(self, editor, option, index):
        editor.setGeometry(option.rect)

class myQSqlTableModel1(QtSql.QSqlTableModel):
    def flags(self, index):
        result = QtSql.QSqlTableModel.flags(self, index);
        if index.column() == 2:
            result |= QtCore.Qt.ItemIsUserCheckable
        return result

    def data(self, index, role):
        if not index.isValid:
            return QtCore.QVariant()
        value = QtSql.QSqlTableModel.data(self, index, role)
        if index.column() == 2:
            if role == QtCore.Qt.CheckStateRole:
                return QtCore.Qt.Unchecked if QtSql.QSqlTableModel.data(self, index).toInt()[0] else QtCore.Qt.Checked
            elif role == QtCore.Qt.DisplayRole:
                return QtCore.QVariant()
        return value


class SpinBoxDelegate(QtGui.QItemDelegate):
    def createEditor(self, parent, option, index):
        editor = QtGui.QSpinBox(parent)
        editor.setMinimum(0)
        editor.setMaximum(100)
        print 'spinbox'
        return editor

    def setEditorData(self, spinBox, index):
        value = index.model().data(index, QtCore.Qt.EditRole).toInt()[0]

        spinBox.setValue(value)

    def setModelData(self, spinBox, model, index):
        spinBox.interpretText()
        value = spinBox.value()

        model.setData(index, value, QtCore.Qt.EditRole)

    def updateEditorGeometry(self, editor, option, index):
        editor.setGeometry(option.rect)


class myQSqlTableModel(QtSql.QSqlTableModel):
    # def __init__(self, parent=None):
    # super(myQSqlTableModel, self).__init__(parent)

    def flags(self, index):
        flag = QtSql.QSqlTableModel.flags(self, index)
        if index.column() == 2:
            flag |= QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled
        return flag

    def data(self, index, role):
        if index.column() == 2:
            value = QtSql.QSqlTableModel.data(self, index, QtCore.Qt.DisplayRole)
            if role == QtCore.Qt.CheckStateRole:
                if value != 0:
                    return QtCore.Qt.Checked
                else:
                    return QtCore.Qt.Unchecked
            else:
                return None
        return QtSql.QSqlTableModel.data(self, index, role)

    def setData(self, index, value, role):
        if index.column() == 2 and role == QtCore.Qt.CheckStateRole:
            # `id` is built-in function
            id_ = self.data(self.index(index.row(), 0)).toString()
            state, ok = value.toInt()
            if state == QtCore.Qt.Checked:
                value = 1
            else:
                value = 0
            result = self.setAniSAOptatus(id_, value)
            if result:
                # we modified the db, we need to query again
                self.refresh()
            return result

        # I don't know what `refresh` does. But normally you don't need that
        return False


    def refresh(self):
        # something that re-queries the model.
        # self.setQuery('SELECT * FROM Shot')
        self.setTable("test")

    def setAniStatus(self, id_, value):
        query = QtSql.QSqlQuery()
        sql = "UPDATE Shot SET Ani= {0} WHERE idShot = {1}".format(value, id_)
        query.prepare(sql)
        print 'lastQuery:', query.lastQuery()
        return query.exec_()


class SpinDelegate1(QtGui.QItemDelegate):
    def __init__(self, parent=None):
        QtGui.QItemDelegate.__init__(self, parent)
        # super(SpinDelegate1, self).__init__(parent=None)
        pass

    def createEditor(self, parent, QStyleOptionViewItem, QModelIndex):
        editor = QtGui.QSpinBox(parent)
        editor.installEventFilter(self)
        editor.setMinimum(0)
        editor.setMaximum(10000)
        return editor

    def setEditorData(self, editor, index):
        value = index.model().data(index, QtCore.Qt.EditRole).toInt()[0]
        editor.setValue(value)

    def setModelData(self, editor, model, index):
        value = editor.value()
        model.setData(index, value, QtCore.Qt.EditRole)

    def updateEditorGeometry(self, editor, option, index):
        editor.setGeometry(option.rect)


class SpinDelegate2(QtGui.QItemDelegate):
    def __init__(self):
        super(SpinDelegate2, self).__init__()
        pass

    def createEditor(self, parent, QStyleOptionViewItem, QModelIndex):
        editor = QtGui.QSpinBox(parent)
        editor.installEventFilter(self)
        editor.setMinimum(0)
        editor.setMaximum(10000)
        return editor

    def setEditorData(self, editor, index):
        value = index.model().data(index, QtCore.Qt.EditRole).toInt()[0]

        editor.setValue(value)

    def setModelData(self, editor, model, index):
        value = editor.value()
        model.setData(index, value, QtCore.Qt.EditRole)

    def updateEditorGeometry(self, editor, option, index):
        editor.setGeometry(option.rect)


class mymodel(QtCore.QAbstractTableModel, object):
    def __init__(self, parent):
        super(mymodel, self).__init__(parent)
        # self._queue = PriorityQueue()
        # self._queue.put((65535, IdleProcess()))
        self.headers = [u'数据']
        self.parent = parent
        self._data = [70, 90, 20, 50]

    def rowCount(self, parent=QtCore.QModelIndex(), *args, **kwargs):
        # return self._queue.qsize()
        return 3

    def columnCount(self, parent=QtCore.QModelIndex(), *args, **kwargs):
        return 1

    def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole):
        if role == QtCore.Qt.DisplayRole and orientation == QtCore.Qt.Horizontal:
            return self.headers[section]

    def data(self, index, role=QtCore.Qt.DisplayRole):
        row, col = index.row(), index.column()

        if not index.isValid() or not (0 <= row < self.rowCount()) or not (0 <= col < self.columnCount()):
            return QtCore.QVariant()

        # 如果当前角色是DisplayRole
        if role == QtCore.Qt.DisplayRole:
            # 返回当前行的数据
            return self._data[row]

        # 如果角色不满足需求，则返回QVariant
        return QtCore.QVariant()


class Main(QtGui.QMainWindow):
    def __init__(self, parent=None):
        super(Main, self).__init__(parent=None)
        self.main_widget = QtGui.QWidget()
        self.setCentralWidget(self.main_widget)
        self.main_widget.setWindowTitle(self.tr("商品信息"))
        self.main_layout = QtGui.QGridLayout(self.main_widget)

        self.table_layout = QtGui.QGridLayout()
        self.funcbottons_layout = QtGui.QHBoxLayout()
        self.details_layout = QtGui.QGridLayout()

        self.main_layout.addLayout(self.table_layout, 0, 0, 1, 1)
        self.main_layout.addLayout(self.funcbottons_layout, 1, 0, 1, 1)
        self.main_layout.addLayout(self.details_layout, 2, 0, 1, 1)

        # 字体风格设置
        self.font_underline = QtGui.QFont()
        self.font_underline.setUnderline(True)
        self.dbconn = kexshop.gtcom.dbpool.Main().dbconn()
        if (self.dbconn):
            pass
        else:
            print u"后台数据库打开失败!"
            QtGui.QMessageBox.critical(self, u"错误", u"后台数据库打开失败!")
            sys.exit(0)
        # self.dbconnname = "gtdbconn"
        # self.dbconn = QtSql.QSqlDatabase.addDatabase("QPSQL", self.dbconnname)
        # self.dbconn.setHostName("gtlions")
        # self.dbconn.setDatabaseName("gtlions")
        # self.dbconn.setPort(5432)
        # self.dbconn.setUserName("gtlions")
        # self.dbconn.setPassword("000000")
        # self.dbconn.open()
        # 数据表格窗口
        self.table_tableview = QtGui.QTableView(self)
        # self.palette_red = QtGui.QPalette()
        # self.palette_red.setColor(QtGui.QPalette.Base, QtGui.QColor(255, 0, 0))
        #
        # self.table_tableview.setBackgroundRole(QtGui.QPalette.HighlightedText)

        self.table_tableview.clicked.connect(self.tableclicked_do)

        self.table_tablemodel = myQSqlTableModel1(parent=self.table_tableview, db=self.dbconn)
        # self.table_tablemodel = QtSql.QSqlTableModel(parent=self.table_tableview, db=self.dbconn)
        self.table_tablemodel.setEditStrategy(QtSql.QSqlTableModel.OnFieldChange)
        self.table_tablemodel.setTable("test")

        self.table_tableview.setModel(self.table_tablemodel)
        # de = QtGui.QItemDelegate()
        # self.table_tableview.setItemDelegate(de)
        # self.table_tableview.setItemDelegate(mydelegate(self.table_tablemodel,self.table_tableview))
        # self.table_tableview.setItemDelegateForColumn(2, SpinDelegate1(self.table_tableview))
        # self.table_tableview.setItemDelegateForColumn(3, SpinDelegate1(self.table_tableview))

        #
        self.table_tableview.setSortingEnabled(True)
        self.table_tableview.sortByColumn(0, 0)
        # self.table_tableview.hideColumn(0)
        # # self.model.setSort(2, 1)
        # self.table_tablemodel.setHeaderData(1, QtCore.QtCore.Qt.Horizontal, u'名称')
        # self.table_tablemodel.setHeaderData(2, QtCore.QtCore.Qt.Horizontal, u'编号')
        # self.table_tablemodel.setHeaderData(3, QtCore.QtCore.Qt.Horizontal, u'型号')
        # self.table_tablemodel.setHeaderData(4, QtCore.QtCore.Qt.Horizontal, u'单位')
        # self.table_tablemodel.setHeaderData(5, QtCore.QtCore.Qt.Horizontal, u'规格')
        # self.table_tablemodel.setHeaderData(6, QtCore.QtCore.Qt.Horizontal, u'备注')
        # self.table_tablemodel.setHeaderData(7, QtCore.QtCore.Qt.Horizontal, u'零售价')
        # self.table_tablemodel.setHeaderData(8, QtCore.QtCore.Qt.Horizontal, u'最低售价')
        # self.table_tablemodel.setHeaderData(9, QtCore.QtCore.Qt.Horizontal, u'折扣')
        # self.table_tablemodel.select()
        self.table_layout.addWidget(self.table_tableview, 1, 0)

        # 按钮窗口
        self.funcbottons_lb_tips = QtGui.QLabel(u'一共有 ' + str(self.table_tablemodel.rowCount()) + u' 条数据信息')
        self.funcbottons_refresh_bt = kexshop.gtcom.buttonlist.ButtonRefresh()
        self.funcbottons_refresh_bt.clicked.connect(self.refresh_do)
        self.funcbottons_search_bt = kexshop.gtcom.buttonlist.ButtonSearch()
        self.funcbottons_search_bt.clicked.connect(self.search_do)
        self.funcbottons_add_bt = kexshop.gtcom.buttonlist.ButtonAdd()
        self.funcbottons_add_bt.clicked.connect(self.add_do)
        self.funcbottons_delete_bt = kexshop.gtcom.buttonlist.ButtonDelete()
        self.funcbottons_delete_bt.clicked.connect(self.del_do)
        self.funcbottons_layout.addWidget(self.funcbottons_lb_tips)
        self.funcbottons_layout.addStretch()
        self.funcbottons_layout.addWidget(self.funcbottons_refresh_bt)
        self.funcbottons_layout.addWidget(self.funcbottons_search_bt)
        self.funcbottons_layout.addWidget(self.funcbottons_add_bt)
        self.funcbottons_layout.addWidget(self.funcbottons_delete_bt)

        # 明细及其其他窗口
        self.details_widget = QtGui.QTabWidget()
        self.details_layout.addWidget(self.details_widget)

        self.details_show_widget = QtGui.QWidget()
        self.details_show_layout = QtGui.QGridLayout(self.details_show_widget)
        self.details_search_widget = QtGui.QWidget()
        self.details_search_layout = QtGui.QGridLayout(self.details_search_widget)
        self.details_add_widget = QtGui.QWidget()
        self.details_add_layout = QtGui.QGridLayout(self.details_add_widget)

        self.details_widget.addTab(self.details_show_widget, QtGui.QIcon('resources/more.png'), u'明细信息')
        self.details_widget.addTab(self.details_search_widget, QtGui.QIcon('resources/search.png'), u'查询搜索')
        self.details_widget.addTab(self.details_add_widget, QtGui.QIcon('resources/search.png'), u'增加信息')

        # 明细信息标签
        self.details_show_currentrowinfo_lb = QtGui.QLabel()
        self.details_show_mc_lb = QtGui.QLabel(u'名称:')
        self.details_show_mc_data_lb = QtGui.QLabel()
        self.details_show_mc_data_lb.setFont(self.font_underline)
        self.details_show_bh_lb = QtGui.QLabel(u'编号:')
        self.details_show_bh_data_lb = QtGui.QLabel()
        self.details_show_bh_data_lb.setFont(self.font_underline)
        self.details_show_xh_lb = QtGui.QLabel(u'型号:')
        self.details_show_xh_data_lb = QtGui.QLabel()
        self.details_show_xh_data_lb.setFont(self.font_underline)
        self.details_show_dw_lb = QtGui.QLabel(u'单位:')
        self.details_show_dw_data_lb = QtGui.QLabel()
        self.details_show_dw_data_lb.setFont(self.font_underline)
        self.details_show_gg_lb = QtGui.QLabel(u'规格:')
        self.details_show_gg_data_lb = QtGui.QLabel()
        self.details_show_gg_data_lb.setFont(self.font_underline)
        self.details_show_bz_lb = QtGui.QLabel(u'备注:')
        self.details_show_bz_data_lb = QtGui.QLabel()
        self.details_show_bz_data_lb.setFont(self.font_underline)
        self.details_show_lsj_lb = QtGui.QLabel(u'零售价:')
        self.details_show_lsj_data_lb = QtGui.QLabel()
        self.details_show_lsj_data_lb.setFont(self.font_underline)

        self.details_show_layout.addWidget(self.details_show_currentrowinfo_lb, 0, 0, 1, 1)
        self.details_show_layout.addWidget(self.details_show_mc_lb, 1, 0, 1, 1)
        self.details_show_layout.addWidget(self.details_show_mc_data_lb, 1, 1, 1, 1)
        self.details_show_layout.addWidget(self.details_show_bh_lb, 1, 2, 1, 1)
        self.details_show_layout.addWidget(self.details_show_bh_data_lb, 1, 3, 1, 1)
        self.details_show_layout.addWidget(self.details_show_xh_lb, 1, 4, 1, 1)
        self.details_show_layout.addWidget(self.details_show_xh_data_lb, 1, 5, 1, 1)
        self.details_show_layout.addWidget(self.details_show_dw_lb, 2, 0, 1, 1)
        self.details_show_layout.addWidget(self.details_show_dw_data_lb, 2, 1, 1, 1)
        self.details_show_layout.addWidget(self.details_show_gg_lb, 2, 2, 1, 1)
        self.details_show_layout.addWidget(self.details_show_gg_data_lb, 2, 3, 1, 1)
        self.details_show_layout.addWidget(self.details_show_bz_lb, 2, 4, 1, 1)
        self.details_show_layout.addWidget(self.details_show_bz_data_lb, 2, 5, 1, 1)
        self.details_show_layout.addWidget(self.details_show_lsj_lb, 3, 0, 1, 1)
        self.details_show_layout.addWidget(self.details_show_lsj_data_lb, 3, 1, 1, 1)

        # 查询搜索标签

        # 增加信息标签
        self.details_add_mc_lb = QtGui.QLabel(u'名称')
        self.details_add_mc_data_le = QtGui.QLineEdit()
        self.details_add_bh_lb = QtGui.QLabel(u'编号')
        self.details_add_bh_data_le = QtGui.QLineEdit()
        self.details_add_xh_lb = QtGui.QLabel(u'型号')
        self.details_add_xh_data_le = QtGui.QLineEdit()
        self.details_add_dw_lb = QtGui.QLabel(u'单位')
        self.details_add_dw_data_le = QtGui.QLineEdit()
        self.details_add_gg_lb = QtGui.QLabel(u'规格')
        self.details_add_gg_data_le = QtGui.QLineEdit()
        self.details_add_bz_lb = QtGui.QLabel(u'备注')
        self.details_add_bz_data_le = QtGui.QLineEdit()
        self.details_add_lsj_lb = QtGui.QLabel(u'零售价')
        self.details_add_lsj_data_le = QtGui.QLineEdit()

        self.details_add_confirm_bt = QtGui.QPushButton(u'保存')
        self.details_add_confirm_bt.setIcon(QtGui.QIcon('resources/confirm.png'))
        self.details_add_clearinput_bt = QtGui.QPushButton(u'清空输入框')
        self.details_add_clearinput_bt.setIcon(QtGui.QIcon('resources/delete.png'))
        QtCore.QObject.connect(self.details_add_confirm_bt, QtCore.SIGNAL('clicked()'), self.add_confirm_do)
        QtCore.QObject.connect(self.details_add_clearinput_bt, QtCore.SIGNAL('clicked()'), self.add_clearinput_do)
        self.details_add_layout.addWidget(self.details_add_mc_lb, 0, 0, 1, 1)
        self.details_add_layout.addWidget(self.details_add_mc_data_le, 0, 1, 1, 1)
        self.details_add_layout.addWidget(self.details_add_bh_lb, 0, 2, 1, 1)
        self.details_add_layout.addWidget(self.details_add_bh_data_le, 0, 3, 1, 1)
        self.details_add_layout.addWidget(self.details_add_xh_lb, 1, 0, 1, 1)
        self.details_add_layout.addWidget(self.details_add_xh_data_le, 1, 1, 1, 1)
        self.details_add_layout.addWidget(self.details_add_dw_lb, 1, 2, 1, 1)
        self.details_add_layout.addWidget(self.details_add_dw_data_le, 1, 3, 1, 1)
        self.details_add_layout.addWidget(self.details_add_gg_lb, 2, 0, 1, 1)
        self.details_add_layout.addWidget(self.details_add_gg_data_le, 2, 1, 1, 1)
        self.details_add_layout.addWidget(self.details_add_bz_lb, 2, 2, 1, 1)
        self.details_add_layout.addWidget(self.details_add_bz_data_le, 2, 3, 1, 1)
        self.details_add_layout.addWidget(self.details_add_lsj_lb, 3, 0, 1, 1)
        self.details_add_layout.addWidget(self.details_add_lsj_data_le, 3, 1, 1, 1)
        self.details_add_layout.addWidget(self.details_add_confirm_bt, 4, 0, 1, 1)
        self.details_add_layout.addWidget(self.details_add_clearinput_bt, 4, 2, 1, 1)

    def tableclicked_do(self):
        self.details_widget.setCurrentWidget(self.details_show_widget)
        row = self.table_tableview.currentIndex().row()
        self.details_show_currentrowinfo_lb.setText(u"当前正在查看第【" + str(row + 1) + u"】行数据信息")
        reocrd = self.table_tablemodel.record(row)
        column = reocrd.count()
        self.details_show_mc_data_lb.setText(reocrd.value(0).toString())
        self.details_show_bh_data_lb.setText(reocrd.value(1).toString())
        self.details_show_xh_data_lb.setText(reocrd.value(2).toString())
        self.details_show_dw_data_lb.setText(reocrd.value(3).toString())
        self.details_show_gg_data_lb.setText(reocrd.value(4).toString())
        self.details_show_bz_data_lb.setText(reocrd.value(5).toString())
        self.details_show_lsj_data_lb.setText(reocrd.value(6).toString())

    def refresh_do(self):
        # self.wd_datadetails.setCurrentWidget(self.wd_datadetail_show)
        self.table_tablemodel.select()
        self.funcbottons_lb_tips.setText(u'一共有 ' + str(self.table_tablemodel.rowCount()) + u' 条数据信息')

    def search_do(self):
        self.details_widget.setCurrentWidget(self.details_search_widget)
        # widget_query = QtGui.QDialog(self)
        # widget_query.setModal(True)
        # ly_widget_query = QtGui.QGridLayout(widget_query)
        #
        # lb_mc = QtGui.QLabel(u'名称')
        # le_mc = QtGui.QLineEdit()
        # lb_bh = QtGui.QLabel(u'编号')
        # le_bh = QtGui.QLineEdit()
        # lb_dw = QtGui.QLabel(u'单位')
        # le_dw = QtGui.QLineEdit()
        # lb_gg = QtGui.QLabel(u'规格')
        # le_gg = QtGui.QLineEdit()
        # lb_xh = QtGui.QLabel(u'型号')
        # le_xh = QtGui.QLineEdit()
        # lb_bz = QtGui.QLabel(u'备注')
        # le_bz = QtGui.QLineEdit()
        # lb_lsj = QtGui.QLabel(u'零售价')
        # le_lsj = QtGui.QLineEdit()
        # lb_zdsj = QtGui.QLabel(u'最低售价')
        # le_zdsj = QtGui.QLineEdit()
        # ly_widget_query.addWidget(lb_mc, 0, 0, 1, 1)
        # ly_widget_query.addWidget(le_mc, 0, 1, 1, 1)
        # ly_widget_query.addWidget(lb_bh, 0, 2, 1, 1)
        # ly_widget_query.addWidget(le_bh, 0, 3, 1, 1)
        # ly_widget_query.addWidget(lb_dw, 1, 0, 1, 1)
        # ly_widget_query.addWidget(le_dw, 1, 1, 1, 1)
        # ly_widget_query.addWidget(lb_gg, 1, 2, 1, 1)
        # ly_widget_query.addWidget(le_gg, 1, 3, 1, 1)
        # ly_widget_query.addWidget(lb_xh, 2, 0, 1, 1)
        # ly_widget_query.addWidget(le_xh, 2, 1, 1, 1)
        # ly_widget_query.addWidget(lb_bz, 2, 2, 1, 1)
        # ly_widget_query.addWidget(le_bz, 2, 3, 1, 1)
        # ly_widget_query.addWidget(lb_lsj, 3, 0, 1, 1)
        # ly_widget_query.addWidget(le_lsj, 3, 1, 1, 1)
        # ly_widget_query.addWidget(lb_zdsj, 3, 2, 1, 1)
        # ly_widget_query.addWidget(le_zdsj, 3, 3, 1, 1)
        # widget_query.show()
        self.table_tablemodel.select()

    def add_do(self):
        self.details_widget.setCurrentWidget(self.details_add_widget)
        print 'add-1'

    def add_confirm_do(self):
        print 'add-2'
        record = self.table_tablemodel.record()
        dbquery = QtSql.QSqlQuery(self.dbconn)
        dbquery.exec_("select nextval('devhis1_id_seq')")
        dbquery.next()
        nextid = dbquery.value(0).toInt()[0]
        print nextid
        record.setValue("id", nextid)
        record.setValue("msg1", self.details_add_mc_data_le.text())
        record.setValue("msg2", self.details_add_bh_data_le.text())
        record.setValue("msg3", self.details_add_dw_data_le.text())
        record.setValue("ctime1", self.details_add_gg_data_le.text())
        record.setValue("ctime2", self.details_add_xh_data_le.text())
        record.setValue("ctime3", self.details_add_bz_data_le.text())
        self.table_tablemodel.insertRecord(0, record)
        self.table_tablemodel.submitAll()
        self.refresh_do()

    def add_clearinput_do(self):
        self.details_add_mc_data_le.clear()
        self.details_add_bh_data_le.clear()
        self.details_add_xh_data_le.clear()
        self.details_add_dw_data_le.clear()
        self.details_add_gg_data_le.clear()
        self.details_add_bz_data_le.clear()
        self.details_add_lsj_data_le.clear()

    def del_do(self):
        currow = self.table_tableview.currentIndex().row()
        if currow == -1:
            QtGui.QMessageBox.information(self, self.tr("没有选择任何数据信息"), self.tr("没有选择任何数据信息,请将鼠标在要删除的数据信息的行上点击"),
                                          QtGui.QMessageBox.Ok)
        else:
            ok = QtGui.QMessageBox.warning(self, u"删除数据",
                                           u"是否真的要删除第【" + str(currow + 1) + u"】行数据信息?",
                                           QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
                                           QtGui.QMessageBox.Yes)
            if ok == QtGui.QMessageBox.Yes:
                self.table_tablemodel.removeRow(currow)
                self.refresh_do()


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    main = Main()
    main.show()
    sys.exit(app.exec_())